module.exports = app => {
    const { STRING, INTEGER, TEXT } = app.Sequelize;

    const TopicLessonQuestionBank = app.model.define('topic-lesson-question-bank', {
        lessonId: {
            type: INTEGER,
            allowNull: false,
        },
        title: { // 题干
            type: STRING(512),
            allowNull: false,
        },
        type: {
            type: STRING(),
            allowNull: false,
        },
        options: {  // 选项
            type: TEXT,
            allowNull: false,

            get() {
                return this.getDataValue('options') ? JSON.parse(this.getDataValue('options')) : null;
            },
            set(value) {
                this.setDataValue('options', JSON.stringify(value));
            }
        },
        correctAnswers: { // 正确答案
            type: TEXT,
            allowNull: false,
        },
    }, {
        timestamps: true,
        underscored: false,
    });

    // TopicLessonQuestionBank.associate = function () {
    //     TopicLessonQuestionBank.Topic = TopicLessonQuestionBank.belongsTo(app.model.TopicLesson, {
    //         foreignKey: "lessonId",
    //         as: "lesson"
    //     });
    // };


    return TopicLessonQuestionBank;
};
